﻿using Expression;
using Expression.Interface;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace JsonParse
{

    class Program
    { 
        static void Main(string[] args)
        {


            //数据准备
            List<Data> datas = new List<Data>();
            datas.Add(new Data()
            {
                Current = 47.2,
                Power = 17.179192,
                MPDCurrent = 1.157353429,
                D1_Data = 0.453244047,
                D2_Data = 0.001460859,
                Temperature = 25
            });
            datas.Add(new Data()
            {
                Current = 47.6,
                Power = 17.360087,
                MPDCurrent = 1.167957429,
                D1_Data = 0.454268309,
                D2_Data = 0.001305233,
                Temperature = 25
            });
            datas.Add(new Data()
            {
                Current = 48,
                Power = 17.54086,
                MPDCurrent = 1.178465571,
                D1_Data = 0.455104662,
                D2_Data = 0.000985303,
                Temperature = 25,
            });
            datas.Add(new Data()
            {
                Current = 48.4,
                Power = 17.722561,
                MPDCurrent = 1.157353429,
                D1_Data = 0.45568005,
                D2_Data = 0.000391148,
                Temperature = 25
            });
            datas.Add(new Data()
            {
                Current = 48.8,
                Power = 17.904714,
                MPDCurrent = 1.199172857,
                D1_Data = 0.456339186,
                D2_Data = -0.000204686,
                Temperature = 25
            }); 


            Stopwatch watch = new Stopwatch();
            watch.Start();
            List<IArg> inputs = new List<IArg>();
            inputs.Add(new ArgUser() { Name = "arg0", Display = "温度1", Value = "25", DataType = "double" });
            inputs.Add(new ArgUser() { Name = "arg1", Display = "温度2", Value = "85", DataType = "double" });
            inputs.Add(new ArgUser() { Name = "arg2", Display = "功率", Value = "17.3", DataType = "double" });
 
            List<IConditional> querys = new List<IConditional>();

            Conditional conditional = new Conditional()
            {
                Assign = new List<string>() { "arg3 = Current", "arg4 = MPDCurrent" },
                Condition = "d.Power == like(arg2,\"d.Power\",\"d.Temperature = arg0\") && d.Temperature == arg0"
            };
            querys.Add(conditional);
            Algorithm algorithm = new Algorithm()
            {

                UserParameters = inputs,
                Conditions = null,
                Expression = "arg1 + arg2 + arg0",
                Name = "测试算法"
            }; 
            AlgorithmProcess<Data> process = new AlgorithmProcess<Data>(datas, algorithm);
            Console.WriteLine($"算法结果：{process.Execute()}"); 
            watch.Stop();  
            Console.WriteLine($"整体耗时：{watch.Elapsed.TotalSeconds}");

            ////自定义函数测试
            //Point pt1 = new Point(1.34, 3.45);
            //Point pt2 = new Point(44.34, 56.45);

            //ArgUser a = new ArgUser()
            //{
            //    DataType = "point",
            //    Display = "p1",
            //    Name = "arg_0",
            //    Value = "(1.34,3.45)"
            //};
            //ArgUser a1 = new ArgUser()
            //{
            //    DataType = "point",
            //    Display = "p2",
            //    Name = "arg_1",
            //    Value = "(44.34, 56.45)"
            //};
            //process.AddParameters(a);
            //process.AddParameters(a1);
            //Console.WriteLine(process.Eval("ith1(arg_0,arg_1)"));



            Console.ReadLine();






        }

      

   
        

    }
 


   
    public class Data
    {
        public double Current { get; set; }
        public double Power { get; set; }
        public double MPDCurrent { get; set; }
        public double Temperature { get; set; }
        public int HoleId { get; set; }
        public double D1_Data { get; set; }
        public double D2_Data { get; set; }



    }  









}
